In [9]:
from __future__ import division, print_function
import os, glob
import numpy as np
import matplotlib.pyplot as plt
from rvseg import patient
%matplotlib inline
In [10]:
basedir = "/home/paperspace/Developer/datasets/rvsc/TrainingSet"
datadir = os.path.join(basedir, "patient09")
p = patient.PatientData(datadir)
In [14]:
for index in range(len(p.images)):
plt.figure(figsize=(10,5))
plt.subplot(1, 2, 1)
plt.axis("off")
plt.imshow(p.images[index], cmap=plt.cm.gray)
plt.subplot(1, 2, 2)
plt.axis("off")
plt.imshow(p.images[index], cmap=plt.cm.gray)
plt.plot(*p.endocardium_contours[index], color='springgreen')
plt.plot(*p.epicardium_contours[index], color='orchid')
In [ ]:
from scipy import interpolate
In [31]:
dices = []
stride = 40
for n in range(len(p.images)):
image = p.images[n]
x, y = p.endocardium_contours[n]
x1 = np.concatenate((x[::stride], [x[n]]))
y1 = np.concatenate((y[::stride], [y[n]]))
tck, u = interpolate.splprep((x1, y1), s=0)
unew = np.arange(0, 1.01, 0.01)
x2, y2 = interpolate.splev(unew, tck)
mask1 = p.endocardium_masks[n]
mask2 = p.contour_to_mask(x2, y2, norm=1)
dice = 2 * np.sum(mask1 * mask2) / (np.sum(mask1) + np.sum(mask2))
dices.append(dice)
print(len(x), dice)
plt.figure(figsize=(10,5))
plt.subplot(1, 2, 1)
plt.axis("off")
plt.imshow(image, cmap=plt.cm.gray)
plt.subplot(1, 2, 2)
plt.axis("off")
plt.imshow(image, cmap=plt.cm.gray)
plt.plot(x, y)
plt.plot(x2, y2)
print(np.mean(dices), np.std(dices))
In [36]:
base = "/home/paperspace/Developer/work/rvsc/"
paths = [
base + "aaug/1e-3/unet-aaug",
base + "mnt/dilated-unet/aaug/1e-3/dilated-unet-aaug",
base + "dilated-densenet/aaug/8-layer-24-features/dilated-densenet-8-24-aaug"
]
paths = [
base + "eaug/1e-3/unet-eaug",
base + "mnt/dilated-unet/eaug/1e-3/dilated-unet-eaug",
base + "dilated-densenet/eaug/8-layer-24-features/dilated-densenet-8-layer-24-features"
]
DICE, JACCARD = 0, 1
train = []
val = []
for path in paths:
train.append(np.loadtxt(path + ".train").T[DICE])
val.append(np.loadtxt(path + ".val").T[DICE])
plt.figure(figsize=(10,5))
plt.subplot(1, 2, 1)
plt.boxplot(train)
plt.ylim(-0.03, 1.03)
plt.ylabel("training dice coefficient")
plt.xticks([1, 2, 3], ["u-net", "dilated u-net", "dilated densenet"])
plt.subplot(1, 2, 2)
plt.boxplot(val)
plt.ylim(-0.03, 1.03)
plt.ylabel("validation dice coefficient")
plt.xticks([1, 2, 3], ["u-net", "dilated u-net", "dilated densenet"])
Out[36]: